<!-- <script lang="ts" setup>
import { stringify } from 'superjson'
import '~/utils/polyfill'
import { useMenuStore } from '~/stores/menu'
import { useUserStore } from '~/stores/user'
import '~/styles'

const props = defineProps<{
  error: {
    url?: string
    statusCode?: number
    statusMessage?: string
    message?: string
  }
}>()

// 设置头部属性
const { t } = useI18n()
useDefaultHead({
  title: `${
    props.error?.statusCode === 404
      ? t('common.pageNotFound')
      : t('common.serverError')
  }_${t('app.title')}`,
})

if (props.error?.statusCode === 404) {
  // 只有 404 状态下才进行的初始化
  // 菜单 store 相关初始化
  const menuStore = useMenuStore()
  await menuStore.init()
  onMounted(async () => {
    // 用户 store 相关初始化
    const userStore = useUserStore()
    await userStore.init({ rehydrate: true })
  })
} else {
  // 其余错误只打印错误
  if (import.meta.server) {
    console.dir(props.error, {
      depth: null,
    })
  } else {
    console.error(props.error)
    if (!import.meta.dev) {
      // 发送埋点
      const { sendEvent } = useTracking()
      sendEvent({
        rsCode: 'gn_app_error_log',
        rsName: '应用错误日志',
        eventCode: 'click',
        eventContext: {
          errorMsg: stringify(props.error),
        },
      })
    }
  }
}
</script>

<template>
  <AntdProvider>
    <NuxtLayout name="full-page">
      <div class="flex min-h-[75vh] items-center">
        <Empty
          :type="
            props.error?.statusCode === 404 ? 'page-not-found' : 'server-error'
          "
        />
      </div>
    </NuxtLayout>
  </AntdProvider>
</template> -->
